package com.caiheng.api.controller.platform;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.caiheng.api.entity.platform.UrlScheme;
import com.caiheng.api.service.platfom.UrlSchemeService;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 *@Author: ZhouWei
 *@Description:  通知公告类 相关接口
 *@Date 2018-05-10
 */
@Component
@Controller
public class UrlSchemeController {

    @Resource
    private UrlSchemeService urlSchemeService;

    /**
     *  重新获取配置信息
     * @param
     * @throws Exception
     */
    @GetMapping("/s/{code}")//url:模块/资源/{}/细分
    public String getSign(@PathVariable(value = "code",required = true) String code,Model model) throws Exception{
        QueryWrapper<UrlScheme> qw = new QueryWrapper<>();
        qw.eq("url_code",code);
        qw.last("limit 1");
        UrlScheme urlScheme = urlSchemeService.getOne(qw);
        if(urlScheme != null){
            model.addAttribute("url",urlScheme.getUrlScheme());
            return "mini";
        }
        return "error";
    }

//    /**
//     *  重新获取配置信息
//     * @param
//     * @throws Exception
//     */
//    @GetMapping("/s/{code}")//url:模块/资源/{}/细分
//    public JSONObject getSign(@PathVariable(value = "code",required = true) String code) throws Exception{
//        JSONObject result = null;
//        Map<String,Object> map = new HashMap<>();
//        try{
//            QueryWrapper<UrlScheme> qw = new QueryWrapper<>();
//            qw.eq("url_code",code);
//            qw.last("limit 1");
//            UrlScheme urlScheme = urlSchemeService.getOne(qw);
//            if(urlScheme == null){
//                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该链接不存在"),true,true);
//            }
//
//            if(urlScheme.getIsExpire() == 1 && urlScheme.getExpireTime().getTime() < new Date().getTime()){
//                return Tools.getJson(new GsonResultBean<>(ResponseCode.FAIL,"该链接已过期"),true,true);
//            }
//
//            result = Tools.getJson(new GsonResultBean<>(ResponseCode.OK,"成功",urlScheme.getUrlScheme()),true,false);
//        }catch (Exception e){
//            e.printStackTrace();
//            result = Tools.getJson(new GsonResultBean<>(ResponseCode.ERROR,"系统异常",e.getMessage()),true,true);
//            System.out.println(e.getMessage());
//        }
//        return result;
//    }
}
